package com.atfusu.service.impl;

import com.atfusu.base.BaseDao;
import com.atfusu.base.impl.BaseServiceImpl;
import com.atfusu.bean.entity.UserFollow;
import com.atfusu.bean.vo.UserFollowVo;
import com.atfusu.dao.UserFollowDao;
import com.atfusu.service.DictService;
import com.atfusu.service.UserFollowService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Title:
 * Author: fusu
 * DateTime:  2022/12/3
 * Description:
 **/
@DubboService
public class UserFollowServiceImpl extends BaseServiceImpl<UserFollow> implements UserFollowService {

    @Autowired
    private UserFollowDao userFollowDao;

    @DubboReference
    private DictService dictService;

    @Override
    protected BaseDao<UserFollow> getEntityDao() {
        return userFollowDao;
    }

    @Override
    public void follow(Long houseId, Long id) {
        userFollowDao.follow(houseId, id);
    }

    @Override
    public Boolean isFollow(Long houseId, Long id) {
        UserFollow userFollow = userFollowDao.getByUserIdAndHouseId(houseId, id);
        if (userFollow != null) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public PageInfo<UserFollowVo> findListPage(Integer pageNum, Integer pageSize, Long userId) {
        PageHelper.startPage(pageNum, pageSize);
        List<UserFollowVo> userFollowVoList = userFollowDao.findListPage(userId);
        for (UserFollowVo userFollowVo : userFollowVoList) {
            userFollowVo.setHouseTypeName(dictService.getNameById(userFollowVo.getHouseTypeId()));
            userFollowVo.setFloorName(dictService.getNameById(userFollowVo.getFloorId()));
            userFollowVo.setDirectionName(dictService.getNameById(userFollowVo.getDirectionId()));
        }
        return new PageInfo<UserFollowVo>(userFollowVoList, 5);
    }

    @Override
    public void cancelFollow(Long houseId, Long id) {
        userFollowDao.cancelFollow(houseId, id);
    }
}
